import {
  ModalForm,
  ProFormText,
} from '@ant-design/pro-components';
import { useModel } from '@umijs/max';
import React, { PropsWithChildren } from 'react';

interface UpdateFormProps {
  echoRecord:API.ClrInfo;
  children: any;
}
const CreateForm: React.FC<PropsWithChildren<UpdateFormProps>> = ({
  echoRecord,
  children,
}) => {
  const { updateHandler } = useModel('Classroom.model', (model) => ({
    updateHandler: model.updateHandler,
  }));

  return (
    <ModalForm<API.Clr_Update_Body>
      trigger={children}
      title="教室修改"
      initialValues={echoRecord}
      autoFocusFirstInput
      submitTimeout={2000}
      modalProps={{ destroyOnClose: true }}
      onFinish={async (value) => {
        const success = await updateHandler({
          ...value,
          clsr_id: echoRecord.clsr_id,
        });
        return success; // 返回true MODEL FROM 自动销毁
      }}
    >
      <ProFormText
        name="clsr_name"
        label="教室名称"
        placeholder="请输入教室名称"
        rules={[
          { required: true, message: '教室名称不能为空' },
          { min: 2, max: 20, message: '教室名称字数在2-20之间' },
        ]}
      />
    </ModalForm>
  );
};

export default CreateForm;
